package com.leanyuan.publi.dyno;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.leanyuan.publi.domain.Userinfo;
import com.leanyuan.publi.dto.UserInfoDto;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.jdbc.SQL;

public class UserInfoDynaSqlProvider {
    public String selectUserInfoSql(@Param("dto") UserInfoDto userInfoDto, @Param("page") Page<Userinfo> page){
        return new SQL(){
            {
                SELECT("u.*,a.name as 'aname'");
                FROM("userinfo u");
                LEFT_OUTER_JOIN("t_admin a on u.admin_id=a.admin_id");
                if (userInfoDto.getHouse_id()!=null&&!"".equals(userInfoDto.getHouse_id())){
                    LEFT_OUTER_JOIN("house h on u.user_id=h.user_id");
                    WHERE("h.house_id=#{dto.house_id}");
                }
                if(userInfoDto.getName()!=null&&!"".equals(userInfoDto.getName())){
                    WHERE("username=#{dto.name}");
                }
                if(userInfoDto.getTel()!=null&&!"".equals(userInfoDto.getTel())){
                    WHERE("tel=#{dto.tel}");
                }
                WHERE("userinfocondition='0'");
            }
        }.toString();
    }
}
